package com.ibeeking.found.cop.b.rest.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ibeeking.found.cop.b.rest.service.IMsgKnowledgeGroupService;
import com.ibeeking.found.cop.b.rest.service.IMsgKnowledgeService;
import com.ibeeking.found.cop.service.common.param.MsgKnowledgeGroupParam;
import com.ibeeking.found.cop.service.common.param.MsgKnowledgeParam;
import com.ibeeking.found.cop.service.common.query.MsgKnowledgeGroupQuery;
import com.ibeeking.found.cop.service.common.query.MsgKnowledgePageQuery;
import com.ibeeking.found.cop.service.common.query.MsgKnowledgeQuery;
import com.ibeeking.found.cop.service.common.vo.MsgKnowledgeGroupVO;
import com.ibeeking.found.cop.service.common.vo.MsgKnowledgeVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName MsgKnowledgeController
 * @Description
 * @Author ibeeking
 * @Date 2021-06-02 18:15
 **/
@RestController
@RequestMapping("/b/msgKnowledge/v1")
public class MsgKnowledgeController {

    @Resource
    private IMsgKnowledgeGroupService msgKnowledgeGroupServiceImpl;

    @Resource
    private IMsgKnowledgeService msgKnowledgeServiceImpl;

    /*
     ** 快捷语分组
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询快捷用语分组列表树")
    @PostMapping(value = "/knowledgeGroupTreeList/{parentId}")
    public List<MsgKnowledgeGroupVO> groupTreeList(@PathVariable("parentId") Long parentId) {
        List<MsgKnowledgeGroupVO>  groupVOS = msgKnowledgeGroupServiceImpl.listByParentId(parentId);
        return groupVOS;
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询快捷用语分组列表")
    @PostMapping(value = "/knowledgeGroupList")
    public List<MsgKnowledgeGroupVO> groupList(@RequestBody MsgKnowledgeGroupQuery query) {
        return msgKnowledgeGroupServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "添加快捷用语分组")
    @PostMapping(value = "/knowledgeGroupAdd")
    public Boolean knowledgeGroupAdd(@RequestBody @Validated(BaseValidationGroup.Insert.class) MsgKnowledgeGroupParam param) {
        return msgKnowledgeGroupServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改快捷用语分组")
    @PostMapping(value = "/knowledgeGroupModify")
    public Boolean knowledgeGroupModify(@RequestBody @Validated(BaseValidationGroup.Update.class) MsgKnowledgeGroupParam param) {
        return msgKnowledgeGroupServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查看快捷用语分组详情")
    @GetMapping(value = "/knowledgeGroupView/{id}")
    public MsgKnowledgeGroupVO knowledgeGroupView(@PathVariable("id") Long id) {
        return msgKnowledgeGroupServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除快捷用语分组")
    @GetMapping(value = "/knowledgeGroupDel/{id}")
    public Boolean knowledgeGroupDel(@PathVariable("id") Long id) {
        return msgKnowledgeGroupServiceImpl.del(id);
    }

    /*
     ** 快捷语
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询快捷用语列表")
    @PostMapping(value = "/knowledgeList")
    public List<MsgKnowledgeVO> list(@RequestBody MsgKnowledgeQuery query) {
        return msgKnowledgeServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询快捷用语分页列表")
    @PostMapping(value = "/knowledgePageList")
    public Page<MsgKnowledgeVO> pageList(@RequestBody MsgKnowledgePageQuery pageQuery) {
        return msgKnowledgeServiceImpl.pageList(pageQuery);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "添加快捷用语")
    @PostMapping(value = "/knowledgeAdd")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) MsgKnowledgeParam param) {
        return msgKnowledgeServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改快捷用语")
    @PostMapping(value = "/knowledgeModify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) MsgKnowledgeParam param) {
        return msgKnowledgeServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改是否启用")
    @GetMapping(value = "/changeKnowledgeStatus/{id}/{status}")
    public Boolean changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return msgKnowledgeServiceImpl.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查看快捷用语详情")
    @GetMapping(value = "/knowledgeView/{id}")
    public MsgKnowledgeVO view(@PathVariable("id") Long id) {
        return msgKnowledgeServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除快捷用语")
    @GetMapping(value = "/knowledgeDel/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return msgKnowledgeServiceImpl.del(id);
    }

}
